package com.b2.controller.web;

import com.b2.pojo.entity.CourseCategory;
import com.b2.result.Result;
import com.b2.service.CourseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/web/CourseCategory")
@Slf4j
@Api(tags = "课程分类相关接口")
@CrossOrigin
public class CourseCategoryController {

    // 注入VideoCategoryService的接口对象
    @Resource
    private CourseCategoryService courseCategoryService;

    /**
     * 查看所有的课程类型
     *
     * @return 返回所有课程类型
     */
    @ApiOperation("查看当前用户的课程类型")
    @GetMapping("/check")
    public Result<List<CourseCategory>> check() {
        return courseCategoryService.check();
    }

    /**
     * 添加课程类型
     *
     * @param categoryName 课程类型名
     * @return 返回响应结果
     */
    @ApiOperation("添加课程类型")
    @PostMapping("/add")
    public Result<List<CourseCategory>> add(@ApiParam("课程类型名") @RequestParam(name = "categoryName") String categoryName) {
        return courseCategoryService.add(categoryName);
    }

    /**
     * 删除课程类型
     *
     * @param categoryId 课程类型id
     * @return 返回响应结果
     */
    @ApiOperation("删除课程类型")
    @DeleteMapping("/delete")
    public Result<List<CourseCategory>> delete(@ApiParam("课程类型id") @RequestParam(name = "categoryId") int categoryId) {
        return courseCategoryService.delete(categoryId);
    }
}
